<?php

namespace App\Resource;

use Hyperf\Resource\Json\ResourceCollection;

class ChatFriends extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @return array
     */
    public function toArray(): array
    {
        $data = $this->collection;

        $data->transform(function ($item) {
            return [
                'status' => $item->receiver_fd_count,
                'avatar' => $item->Receiver->avatar,
                'message_types' => $item->Message->types,
                'content' => $item->Message->content,
                'update_time' => strtotime($item['update_time']),
                'update_time_format' => ($item['update_time_format']),
                'unReadNum' => 0,
                'nickname' => $item->Receiver->nickname,
                'user_id' => $item->user_id,
                'receiver_id' => $item->receiver_id,
            ];
        });

        return $data->toArray();
    }
}
